package applications.callcost.listeners;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import applications.callcost.CallListenerService;

public class PhoneListener extends PhoneStateListener{
	
	
	CallListenerService service;
	boolean conversationStarted;
	
	public PhoneListener(CallListenerService s){
		service=s;
	}
	
	public void onCallStateChanged (int state, String incomingNumber){

		//chiamata iniziata
		if(state==TelephonyManager.CALL_STATE_OFFHOOK){
			conversationStarted=true;
		}
		
		//chiamata finita
		else if(state==TelephonyManager.CALL_STATE_IDLE && conversationStarted){
			conversationStarted=false;
			service.showCost();
		}
	}
}
